<?php
namespace Admin\Controller;

class IndexController extends \Think\Controller{
    
    public function index(){
        $this->assign('projectPathName',C('PROJECT_PATH_NAME'));
		//判断是否登录
		$res=array();
		$res=session(C('ADMIN_SESSION'));
        if(empty($res)){
            $this->redirect('Admin/Index/login');
        }
		$this->display();
	}
	
	public function login(){
		$this->display();
	}
	
	//执行登陆
	public function dologin(){
		$arr  = array();
		$name = I("post.name","","trim");
		$pass = I("post.pass","","trim");
		if(empty($name) || empty($pass)){
			die(json_encode(array('res'=>'err','msg'=>'用户名或者密码不能为空，请重新输入！')));
		}
        
		$pass = md5($pass);
		$arr  = M('Suser')->where(array('name'=>$name,'pass'=>$pass))->find();
		if(empty($arr['name'])){
			die(json_encode(array('res'=>'err','msg'=>'用户名或密码错误！')));
		}else{
			session(C('ADMIN_SESSION'),$arr);
			die(json_encode(array('res'=>'suc','msg'=>'登录成功！','url'=>U('Index/index'))));
		}
	}
	
	//退出操作
	public function logout(){
        session(C('ADMIN_SESSION'),null);
        $this->redirect('Admin/Index/login');
    }
    
}